<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>新增询价单</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" type="text/css" href="../../common/bootstrap/css/bootstrap.css" media="all">
	<link rel="stylesheet" type="text/css" href="../../common/layui/css/layui.css" media="all">
	<link rel="stylesheet" type="text/css" href="../../common/global.css" media="all">
	<link rel="stylesheet" type="text/css" href="../../css/customer_list.css" media="all">
	<link rel="stylesheet" type="text/css" href="../../common/module/formSelects/formSelects-v4.css" media="all">
</head>
<style>
	.layui-form-item .layui-input-inline {
		font-size: 14px;
		width: 240px;
		margin-right: 10px;
	}

	.main_content_wrap{
		margin-top: 0px;
	}
	.layui-form-label{
		width: 90px;
	}
	.file-box{
		border: #ededed 1px solid;
		float: left;
		margin-top: 10px;
		margin-left: 25px;
		padding: 10px 15px 0;
		width: 550px;
	}
	.layui-form-item .file-info {
		float: left;
		width: 400px;
		margin-right: 10px;
	}
	.layui-form-item .file-icon {
		float: left;
		width: 95px;
		margin-left: 10px;
	}
	.file-content{
		float: left;
		padding: 15px 10px 0;
		width: 450px;
	}
	.file-box .layui-input-block {
		margin-left: 10px;
	}
	.export-icon{
		font-size: 90px;
		background-color: rgba(232, 255, 249, 0.2);
		border-radius:50px;
	}

	.detail_wrap{
		padding: 0 50px;
	}
	.max_w{
		max-width: 950px;
	}
	.must{
		color: red;
	}
</style>
<body>
<!-- 添加车辆和司机 -->
<div class="layui-fluid content_box">
	<div class="main_content_wrap">
		<form class="layui-form add_form" lay-filter="addForm" action="">
			<p class="add_title">基础信息</p>
			<input hidden name="id" />
			<div class="layui-form-item">

				<label class="layui-form-label"><span class="must">*</span>询价来源</label>
				<div class="layui-input-inline">
					<select name="bus_from_company_id" id="companyList" lay-search lay-verify="required">
					</select>
				</div>

				<label class="layui-form-label">询价人姓名</label>
				<div class="layui-input-inline">
					<input type="text" name="bus_user_name" id="bus_user_name" placeholder="请输入询价人姓名" autocomplete="off" class="layui-input ">
				</div>
				<label class="layui-form-label">询价人电话</label>
				<div class="layui-input-inline">
					<input type="text" name="bus_user_phone" id="bus_user_phone" placeholder="请输入询价人电话" required  lay-verify="phone" class="layui-input">
				</div>
				<label class="layui-form-label">报案号</label>
				<div class="layui-input-inline">
					<input type="text" name="service_no" placeholder="请输入报案号" autocomplete="off" class="layui-input">
				</div>

			</div>
			<div class="layui-form-item">

				<label class="layui-form-label"><span class="must">*</span>车牌号码</label>
				<div class="layui-input-inline">
					<input type="text" name="vehicle_license_num" placeholder="请输入车牌号码"   required  lay-verify="vehicle_license_num"   class="layui-input">
				</div>
				<label class="layui-form-label"><span class="must">*</span>车架号</label>
				<div class="layui-input-inline">
					<input type="text" name="vehicle_frame_no" required  lay-verify="required" placeholder="请输入车架号(VIN)" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-label"><span class="must">*</span>车辆品牌</label>
				<div class="layui-input-inline">
					<input type="text" name="brand_name" id="brand_name" required  lay-verify="required" placeholder="请输入车辆品牌" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-label"><span class="must">*</span>车型名称</label>
				<div class="layui-input-inline">
					<input type="text" name="car_model" placeholder="请输入车型名称" required  lay-verify="required" class="layui-input">
				</div>


			</div>
			<div class="layui-form-item">

				<label class="layui-form-label">修理厂名称</label>
				<div class="layui-input-inline">
					<input type="text" name="repair_company_name" id="repair_company_name" placeholder="请输入修理厂名称" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-label">修理厂电话</label>
				<div class="layui-input-inline">
					<input type="text" name="repair_company_phone" id="repair_company_phone" placeholder="请输入修理厂电话" autocomplete="off" class="layui-input">
				</div>

			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="must">*</span>配件商</label>
				<div class="layui-input-inline" style="width: 22%">
					<select name="bus_to_company_ids" id="subcompany" xm-select="selSubCompany" lay-search lay-verify="required">
					</select>
				</div>

				<label class="layui-form-label"><span class="must">*</span>截止时间</label>
				<div class="layui-input-inline">
					<input type="text" name="deadline_datetime" id="deadline_datetime" placeholder="yyyy-MM-DD HH" lay-verify="required" autocomplete="off" class="layui-input">
				</div>

				<label class="layui-form-label">备注</label>
				<div class="layui-input-inline" style="width: 22%">
					<input type="text" name="common" placeholder="请输入备注" class="layui-input">
				</div>
			</div>
			<p class="add_title">零件清单</p>
			<div class="detail_wrap">
				<div class="layui-form-item">
					<button type="button" class="layui-btn" id="addDetail">
						<i class="layui-icon">&#xe654;</i>新增一行
					</button>
					<button type="button" class="layui-btn" id="upload_file">
						<i class="layui-icon">&#xe67c;</i>导入清单
					</button>
					<div class="layui-inline" id="file_detail" style="display: none">
						<div class="layui-form-item file-box">
							<div class="layui-input-inline file-info">
								<div class="layui-input-block file-content">
									<span id="file_names"></span>
								</div>
								<div class="layui-input-block file-content">
									<span id="file_sizes"></span>
								</div>
							</div>
							<div class="layui-input-inline file-icon">
								<a target="_blank" rel="nofollow" href='javascript:;' id='showInfo' class="layui-btn">预览</a>
							</div>
						</div>
					</div>
					<input hidden name="file_name" id="file_name"/>
					<input hidden name="files" id="file_url"/>
					<input hidden name="file_size" id="file_size"/>
				</div>
				<table class="layui-table max_w" id="infoTable" lay-filter="infoTable"></table>
			</div>
			<!-- 按钮 -->
			<div class="layui-form-item text-center">
				<div class="layui-input-block ">
					<button class="layui-btn site-demo-active" lay-filter="addFormSubmit" lay-submit>确认</button>
				</div>
			</div>
		</form>
	</div>
</div>
<script type="text/html" id="infoTableBar">
	<a class="layui-btn-a" lay-event="del">删除</a>
</script>

<script type="text/javascript" src="../../js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../js/jquery.cookie.js"></script>
<script type="text/javascript" src="../../common/layui/layui2.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/main.js"></script>
<script type="text/javascript" src="../../jsplug/xm-select.js"></script>
<script>
	var id = GetQueryString('id');
	layui.use(['jquery','form','config','upload','laydate', 'admin','table','formSelects'], function(){
		var $ = layui.jquery;
		var form = layui.form;
		var table = layui.table;
		var config = layui.config;
		var upload = layui.upload;
		var laydate = layui.laydate;
		var formSelects = layui.formSelects;
		var admin = layui.admin;

		var companyList = {};
		var suppliersCompanyList = {};

		var currentDate = new Date();
		var oneDayLater = new Date(currentDate);
		oneDayLater.setDate(currentDate.getDate() + 7);

		laydate.render({
			elem: '#deadline_datetime'
			,trigger: 'click',
			type: 'datetime', // 设置类型为 datetime
			format: 'yyyy-MM-dd HH', // 设置显示格式
			value: formatDate(oneDayLater)
		});
		form.render();

		var detailList = []

        var DISABLED = 'layui-btn-disabled';

		send_req('Common/basedata', {}, function (data) {
			companyList = data.company_list;
			suppliersCompanyList = data.suppliers_company_list;
			setSelSales();
			setSelSuppliers();
			if(id){
				getInfo();
			}
		});
        function setSelSales() {
            var companyStr='<option value="">全部企业</option>';
            for(var i=0;i<companyList.length;i++){
                companyStr+='<option value="'+companyList[i].id+'">'+companyList[i].company_name+'</option>';
            }
            $('#companyList').html(companyStr);

            form.render();
        }
		function setSelSuppliers(){
			var subCompanyStr = new Array();
			for (var i = 0; i < suppliersCompanyList.length; i++) {
				subCompanyStr.push({name: suppliersCompanyList[i].suppliers_company_name, value: suppliersCompanyList[i].id});
			}
			formSelects.data('selSubCompany', 'local', {arr: subCompanyStr});

			form.render();
		}

		$("#brand_name").on("input",function(e){
			//获取input输入的值
			var words = e.delegateTarget.value;
			send_req('Common/getSuppliersList', {words:words}, function (data) {
				suppliersCompanyList = data;
				setSelSuppliers();
			});
			form.render();
		});

		$("#bus_user_name").on("input",function(e){
			//获取input输入的值
			var name = e.delegateTarget.value;
			var phone = $("#bus_user_phone").val();
			if(!phone){
				var param = {
					content_type:'user',
					word_type:'name',
					word:name
				}
				getNamePhone(param,"#bus_user_phone");
			}
			form.render();
		});

		$("#bus_user_phone").on("input",function(e){
			//获取input输入的值
			var phone = e.delegateTarget.value;
			var name = $("#bus_user_name").val();
			if(!name){
				var param = {
					content_type:'user',
					word_type:'phone',
					word:phone
				}
				getNamePhone(param,"#bus_user_name");
			}
			form.render();
		});

		$("#repair_company_name").on("input",function(e){
			//获取input输入的值
			var name = e.delegateTarget.value;
			var phone = $("#repair_company_phone").val();
			if(!phone){
				var param = {
					content_type:'repair',
					word_type:'name',
					word:name
				}
				getNamePhone(param,"#repair_company_phone");
			}
			form.render();
		});

		$("#repair_company_phone").on("input",function(e){
			//获取input输入的值
			var phone = e.delegateTarget.value;
			var name = $("#repair_company_name").val();
			if(!name){
				var param = {
					content_type:'repair',
					word_type:'phone',
					word:phone
				}
				getNamePhone(param,"#repair_company_name");
			}
			form.render();
		});

		function getNamePhone(param,id){
			send_req('Common/getNamePhone', param, function (data) {
				if(data){
					$(id).val(data)
				}
				form.render();
			});
		}

		function getInfo(){
			send_req('Inquiry/getInfo', {id:id}, function (data) {
				form.val('addForm',data);
				detailList = data.detail_info;
				if(data.bus_to_company_ids){
					var subcompanys = new Array();
					for (var i = 0; i < data.bus_to_company_ids.length; i++) {
						subcompanys.push(data.bus_to_company_ids[i]);
					}
					formSelects.value('selSubCompany', subcompanys);  // 回显多选框
				}
				form.render();
				tableIns.reload({
					data: detailList // 将新数据与现有缓存合并
				});

				var checked=true;
				setAlldata(checked,'qulity_service_state','qulity_service_state_all');
				setAlldata(checked,'qulity_org_state','qulity_org_state_all');
				setAlldata(checked,'qulity_matching_state','qulity_matching_state_all');
				setAlldata(checked,'qulity_complete_state','qulity_complete_state_all');
				setAlldata(checked,'qulity_suitable_state','qulity_suitable_state_all');
				form.render(); // 更新渲染

			});
		}
		form.render();

		var tableIns = table.render({
			elem: '#infoTable',
			id:'infoTable',
			data:detailList,
			limit:100,
			page: false,
			cols: [[
				{type: 'numbers', title: '序号'},
				{field: 'eq_name', title: '零件名称',edit: true},
				{field: 'oe_no', title: 'OE码',edit: true},
				{field: 'num', title: '数量',edit: true,width: 80},
				{field: 'qulity_service_state', title: '<input type="checkbox" name="qulity_service_state_all" id="qulity_service_state_all" lay-filter="qulity_service_state_all" value="" lay-skin="primary"> 服务站价',
					templet: function(d){
						return '<input type="checkbox" name="qulity_service_state" lay-filter="qulity_service_state" value="' + d.qulity_service_state + '" lay-skin="primary" ' + (d.qulity_service_state ? 'checked' : '') + '> 需要报价';
					}},
				{field: 'qulity_org_state', title: '<input type="checkbox" name="qulity_org_state_all" id="qulity_org_state_all" lay-filter="qulity_org_state_all" value="" lay-skin="primary"> 原厂原包件',
					templet: function(d){
						return '<input type="checkbox" name="qulity_org_state" lay-filter="qulity_org_state" value="' + d.qulity_org_state + '" lay-skin="primary" ' + (d.qulity_org_state ? 'checked' : '') + '> 需要报价';
					}},
				{field: 'qulity_matching_state', title: '<input type="checkbox" name="qulity_matching_state_all" id="qulity_matching_state_all" lay-filter="qulity_matching_state_all" value="" lay-skin="primary"> 配套件',
					templet: function(d){
						return '<input type="checkbox" name="qulity_matching_state" lay-filter="qulity_matching_state" value="' + d.qulity_matching_state + '" lay-skin="primary" ' + (d.qulity_matching_state ? 'checked' : '') + '> 需要报价';
					}},
				{field: 'qulity_complete_state', title: '<input type="checkbox" name="qulity_complete_state_all" id="qulity_complete_state_all" lay-filter="qulity_complete_state_all" value="" lay-skin="primary"> 品牌件',
					templet: function(d){
						return '<input type="checkbox" name="qulity_complete_state" lay-filter="qulity_complete_state" value="' + d.qulity_complete_state + '" lay-skin="primary" ' + (d.qulity_complete_state ? 'checked' : '') + '> 需要报价';
					}},
				{field: 'qulity_suitable_state', title: '<input type="checkbox" name="qulity_suitable_state_all" id="qulity_suitable_state_all" lay-filter="qulity_suitable_state_all" value="" lay-skin="primary"> 适用件',
					templet: function(d){
						return '<input type="checkbox" name="qulity_suitable_state" lay-filter="qulity_suitable_state" value="' + d.qulity_suitable_state + '" lay-skin="primary" ' + (d.qulity_suitable_state ? 'checked' : '') + '> 需要报价';
					}},
				{field: 'common', title: '备注',edit: true},
				{align: 'left', toolbar: '#infoTableBar', title: '操作', width: 80}
			]]
		});

		// 新增一行
		$('#addDetail').click(function (){
			var newData = [
				{
					'eq_name':'',
					'oe_no':'',
					'num':1,
					'qulity_service_state':0,
					'qulity_org_state':0,
					'qulity_matching_state':0,
					'qulity_complete_state':0,
					'qulity_suitable_state':0,
					'common':''
				}
			];
			// 更新表格数据
			tableIns.reload({
				data: table.cache['infoTable'].concat(newData) // 将新数据与现有缓存合并
			});
		});

		// 删除一行
		table.on('tool(infoTable)', function (obj) {
			var data = obj.data;
			var tr = obj.tr; // 当前行的 DOM 元素
			// 方法1: 使用 tr 获取行索引
			var rowIndex = tr.index(); // 这是相对于表格中所有行的索引
			if (obj.event === 'del') { // 删除
				// 从表格缓存中删除该行
				table.cache['infoTable'].splice(rowIndex, 1);
				// 删除对应的 DOM 元素
				obj.del();
				// 移除缓存数组中的 undefined 或 null 元素
				table.cache['infoTable'] = table.cache['infoTable'].filter(function(item) {
					return !Array.isArray(item) || item.length > 0;
				});
				tableIns.reload({
					data: table.cache['infoTable'] // 将新数据与现有缓存合并
				});
			}
		});
		// 修改表格字段
		table.on('edit(infoTable)', function(obj) {
			var value = obj.value //得到修改后的值
				,data = obj.data //得到所在行所有键值
				,field = obj.field; //得到字段
			var tr = obj.tr; // 当前行的 DOM 元素
			// 方法1: 使用 tr 获取行索引
			var rowIndex = tr.index(); // 这是相对于表格中所有行的索引

			if(field === 'num'){
				if(!/^\+?[1-9]\d*$/.test(value)){
					layer.msg('请输入正整数！');
					// 重新设置回原来的值
					// 确保在 DOM 中也更新回原来的值
					obj.update({[field]: 1});
					table.cache['infoTable'][rowIndex].num = 1;
					table.reload('infoTable',{data: table.cache['infoTable']});
					return false;
				}
			}
		});

		/*服务站价全选、取消全选功能*/
		form.on('checkbox(qulity_service_state_all)', function(data){
			var elem = data.elem; // 获得 checkbox 原始 DOM 对象
			var checked = elem.checked; // 获得 checkbox 选中状态

			var checkboxes = document.querySelectorAll('input[type="checkbox"][name="qulity_service_state"]');
			checkboxes.forEach(function(checkbox) {
				checkbox.checked = checked;
			});
			allSetData(checked,'qulity_service_state')
			form.render(); // 更新渲染
		});

		form.on('checkbox(qulity_service_state)', function(data){
			var elem = data.elem; // 获得 checkbox 原始 DOM 对象
			var checked = elem.checked; // 获得 checkbox 选中状态

			// 更新表格
			setData(elem,checked,'qulity_service_state');

			var allCheckboxes = document.querySelectorAll('input[type="checkbox"][name="qulity_service_state"]');
			var checkedCount = Array.from(allCheckboxes).filter(cb => cb.checked).length;
			var selectAllCheckbox = document.getElementById('qulity_service_state_all');
			selectAllCheckbox.checked = checkedCount === allCheckboxes.length;
			form.render(); // 更新渲染
		});
		/*服务站价全选、取消全选功能*/

		/*原厂价全选、取消全选功能*/
		form.on('checkbox(qulity_org_state_all)', function(data){
			var elem = data.elem; // 获得 checkbox 原始 DOM 对象
			var checked = elem.checked; // 获得 checkbox 选中状态

			var checkboxes = document.querySelectorAll('input[type="checkbox"][name="qulity_org_state"]');
			checkboxes.forEach(function(checkbox) {
				checkbox.checked = checked;
			});
			allSetData(checked,'qulity_org_state')
			form.render(); // 更新渲染
		});

		form.on('checkbox(qulity_org_state)', function(data){
			var elem = data.elem; // 获得 checkbox 原始 DOM 对象
			var checked = elem.checked; // 获得 checkbox 选中状态

			// 更新表格
			setData(elem,checked,'qulity_org_state');

			var allCheckboxes = document.querySelectorAll('input[type="checkbox"][name="qulity_org_state"]');
			var checkedCount = Array.from(allCheckboxes).filter(cb => cb.checked).length;
			var selectAllCheckbox = document.getElementById('qulity_org_state_all');
			selectAllCheckbox.checked = checkedCount === allCheckboxes.length;
			form.render(); // 更新渲染
		});
		/*原厂价全选、取消全选功能*/

		/*配套件全选、取消全选功能*/
		form.on('checkbox(qulity_matching_state_all)', function(data){
			var elem = data.elem; // 获得 checkbox 原始 DOM 对象
			var checked = elem.checked; // 获得 checkbox 选中状态

			var checkboxes = document.querySelectorAll('input[type="checkbox"][name="qulity_matching_state"]');
			checkboxes.forEach(function(checkbox) {
				checkbox.checked = checked;
			});
			allSetData(checked,'qulity_matching_state')
			form.render(); // 更新渲染
		});

		form.on('checkbox(qulity_matching_state)', function(data){
			var elem = data.elem; // 获得 checkbox 原始 DOM 对象
			var checked = elem.checked; // 获得 checkbox 选中状态

			// 更新表格
			setData(elem,checked,'qulity_matching_state');

			var allCheckboxes = document.querySelectorAll('input[type="checkbox"][name="qulity_matching_state"]');
			var checkedCount = Array.from(allCheckboxes).filter(cb => cb.checked).length;
			var selectAllCheckbox = document.getElementById('qulity_matching_state_all');
			selectAllCheckbox.checked = checkedCount === allCheckboxes.length;
			form.render(); // 更新渲染
		});
		/*配套件全选、取消全选功能*/

		/*品牌件全选、取消全选功能*/
		form.on('checkbox(qulity_complete_state_all)', function(data){
			var elem = data.elem; // 获得 checkbox 原始 DOM 对象
			var checked = elem.checked; // 获得 checkbox 选中状态

			var checkboxes = document.querySelectorAll('input[type="checkbox"][name="qulity_complete_state"]');
			checkboxes.forEach(function(checkbox) {
				checkbox.checked = checked;
			});

			allSetData(checked,'qulity_complete_state')

			form.render(); // 更新渲染
		});

		form.on('checkbox(qulity_complete_state)', function(data){
			var elem = data.elem; // 获得 checkbox 原始 DOM 对象
			var checked = elem.checked; // 获得 checkbox 选中状态
			// 更新表格
			setData(elem,checked,'qulity_complete_state');

			var allCheckboxes = document.querySelectorAll('input[type="checkbox"][name="qulity_complete_state"]');
			var checkedCount = Array.from(allCheckboxes).filter(cb => cb.checked).length;
			var selectAllCheckbox = document.getElementById('qulity_complete_state_all');
			selectAllCheckbox.checked = checkedCount === allCheckboxes.length;
			form.render(); // 更新渲染
		});
		/*品牌件全选、取消全选功能*/

		/*适用件全选、取消全选功能*/
		form.on('checkbox(qulity_suitable_state_all)', function(data){
			var elem = data.elem; // 获得 checkbox 原始 DOM 对象
			var checked = elem.checked; // 获得 checkbox 选中状态

			var checkboxes = document.querySelectorAll('input[type="checkbox"][name="qulity_suitable_state"]');
			checkboxes.forEach(function(checkbox) {
				checkbox.checked = checked;
			});
			allSetData(checked,'qulity_suitable_state')
			form.render(); // 更新渲染
		});

		form.on('checkbox(qulity_suitable_state)', function(data){
			var elem = data.elem; // 获得 checkbox 原始 DOM 对象
			var checked = elem.checked; // 获得 checkbox 选中状态
			// 更新表格
			setData(elem,checked,'qulity_suitable_state');

			var allCheckboxes = document.querySelectorAll('input[type="checkbox"][name="qulity_suitable_state"]');
			var checkedCount = Array.from(allCheckboxes).filter(cb => cb.checked).length;
			var selectAllCheckbox = document.getElementById('qulity_suitable_state_all');
			selectAllCheckbox.checked = checkedCount === allCheckboxes.length;
			form.render(); // 更新渲染

		});
		/*适配件全选、取消全选功能*/

		function allSetData(checked,qulity){
			table.cache['infoTable'].forEach(function(checkbox) {
				checkbox[qulity] = checked?1:0;
			});
		}

		function setData(elem,checked,qulity){
			// 获取当前行的 <tr> 元素
			var tr = elem.closest('tr'); // 使用 jQuery 的 closest 方法，确保你已引入 jQuery
			// console.log(tr.parentNode.children)
			// 获取当前行的索引
			var index = Array.prototype.indexOf.call(tr.parentNode.children, tr);

			if(qulity === 'qulity_service_state'){
				table.cache['infoTable'][index].qulity_service_state = checked?1:0;
			}else if(qulity === 'qulity_org_state'){
				table.cache['infoTable'][index].qulity_org_state = checked?1:0;
			}else if(qulity === 'qulity_matching_state'){
				table.cache['infoTable'][index].qulity_matching_state = checked?1:0;
			}else if(qulity === 'qulity_complete_state'){
				table.cache['infoTable'][index].qulity_complete_state = checked?1:0;
			}else if(qulity === 'qulity_suitable_state'){
				table.cache['infoTable'][index].qulity_suitable_state = checked?1:0;
			}
		}

		// 设置全选框选择状态
		function setAlldata(checked,qulity,qulityAll){
			var allCheckboxes = document.querySelectorAll('input[type="checkbox"][name="'+qulity+'"]');
			var checkedCount = Array.from(allCheckboxes).filter(cb => cb.checked).length;
			var selectAllCheckbox = document.getElementById(qulityAll);
			selectAllCheckbox.checked = checkedCount === allCheckboxes.length;
			form.render(); // 更新渲染
		}
        var uploadInst = upload.render({
            elem: '#upload_file' //绑定元素
            ,url: access_baseurl + 'File/uploadFile.html'//上传接口
            ,data:{}
            ,accept:'file'
            ,done: function(res){
                layer.closeAll('loading');
                //上传完毕回调
                if(res.success === true){
                    layer.msg('上传成功', {icon: 1,time:300}, function () {
                        $('#file_url').val(res.obj.file);
                        $('#file_size').val(res.obj.file_size);
                        $('#file_name').val(res.obj.file_name);
                        $('#file_detail').show();
                        $('#file_names').html(res.obj.file_name);
                        $('#file_sizes').html(res.obj.file_size_info);
                        var showUrl = 'https://view.officeapps.live.com/op/view.aspx?src=';
                        $('#showInfo').attr('href', showUrl+res.obj.file);
						var file_data = res.obj.data;
						tableIns.reload({
							// data: table.cache['infoTable'].concat(file_data) // 将新数据与现有缓存合并
							data: file_data // 将新数据与现有缓存合并
						});
                        form.render();
                    });
                }else {
                    layer.closeAll('loading');
                    layer.closeAll('page');
                    layer.msg(res.msg, {icon: 2});
                }
				$('#upload_file').removeClass(DISABLED);
				$('#upload_file').removeAttr('disabled');
            }
            ,before: function(obj){
                layer.load(); //上传loading
				// 增加样式
				$('#upload_file').addClass(DISABLED);
				// 增加属性
				$('#upload_file').attr('disabled', 'disabled');
            }
            ,error: function(){
                layer.closeAll('loading');
                layer.closeAll('page');
                //请求异常回调
				$('#upload_file').removeClass(DISABLED);
				$('#upload_file').removeAttr('disabled');
            }
        });


		// 格式化时间为 YYYY-MM-DD HH:mm:ss
		function formatDate(date) {
			var year = date.getFullYear();
			var month = ('0' + (date.getMonth() + 1)).slice(-2);
			var day = ('0' + date.getDate()).slice(-2);
			var hours = ('0' + date.getHours()).slice(-2);
			return year + '-' + month + '-' + day + ' ' + hours;
		}

		//监听提交
		form.on('submit(addFormSubmit)', function(d){
			d.field.detail_info = JSON.stringify(layui.table.cache.infoTable);
			// 增加样式
			$('.site-demo-active').addClass(DISABLED);
			// 增加属性
			$('.site-demo-active').attr('disabled', 'disabled');
			layer.load(); //上传loading
			send_req('Inquiry/addInquiry',d.field,function (res) {
				layer.closeAll('loading');
				layer.msg('提交成功', {icon: 1, time:1500}, function () {
					window.parent.go_to_page_general('./html/inquiry/detail.html','id='+res.id);
					// location.replace('./detail.html?id='+res.id);
				});
			},false)
			return false;
		});


		form.verify({
			phone: function(value, item){ // value：表单的值、item：表单的DOM对象
				if (value !== '') {
					// 正则表达式验证手机号格式
					var mobilePattern = /^1\d{10}$|^(0\d{2,3}-|$0\d{2,3}$|0\d{2,3})?\d{7,8}(-\d{3,4})?$/;
					if (!mobilePattern.test(value)) {
						return '电话格式有误';
					}
				}
			},
            vehicle_license_num:function (value, item){ // value：表单的值、item：表单的DOM对象
            if (value !== '') {
                // 正则表达式验证手机号格式
                var mobilePattern = /^[\d\w\u4e00-\u9fa5()]*$/;
                if (!mobilePattern.test(value)) {
                    return '车牌号有误';
                }
            }
        },
		});
    });
</script>
</body>
</html>